package com.young.servicehosp.service.impl;

import com.young.model.model.hosp.Hospital;
import com.young.servicehosp.repository.HospitalRepository;
import com.young.servicehosp.service.HospitalService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    private HospitalRepository hospitalRepository;


    @Override
    public void saveHospital(Hospital hospital) {

        Hospital byHoscode = hospitalRepository.getByHoscode(hospital.getHoscode());
        //如果已经存在
        if (byHoscode != null) {
            BeanUtils.copyProperties(hospital, byHoscode);
            byHoscode.setUpdateTime(new Date());
            hospitalRepository.save(byHoscode);
        } else {
            hospital.setCreateTime(new Date());
            hospital.setUpdateTime(new Date());
            hospital.setIsDeleted(0);
            hospitalRepository.save(hospital);
        }
    }
}
